async function main() {
    let num = $this.model.table_1758781479488_Kzh64.length; //明细表体

    if (num > 0) {
        for (let i = 0; i < num; i++) {
            let id = $this.$util.uuid(); // 表单id
            let no = $this.$util.uuid(); // 表单no
            let headData = $this.model; // 表头数据
            let bodyData = $this.model.table_1758781479488_Kzh64[i]; // 表体数据

            let allValues = headData["select_1758857498017_QD1rJ"] //产品线

            let tmp1 = [];
            // 1. 建字典
            const PRODUCT_MAP = {
                "9af82f7a8ad26135a66a20610c07448b": "VFD",
                "6855ce85c9ab3661169966589a897338": "HVVF",
                "dc47e2c47ff168600100a3a04517ea07": "SMART",
                "7f1dd99990bc79e22f4628d0c26fdeea": "EVFD",
                "3f1c54bad7d175e988375c731b3d4b63": "APF",
                "04672921c5be8e5abae442e91fca40cc": "NC3S"
            };
            //判断数组存在且非空
            if (Array.isArray(allValues) && allValues.length > 0) {
                for (let j = 0; j < allValues.length; j++) {
                    const key = allValues[j];
                    if (PRODUCT_MAP.hasOwnProperty(key)) {
                        tmp1.push(PRODUCT_MAP[key]);
                    }
                }
            }

            let tmp11 = tmp1.join("、");
            console.log("产品线2 = ", tmp11);

            let allValues2 = headData["select_1758857498017_tDTSt"] //ECR版本

            let tmp2 = []
            const GRADE_MAP = {
                "bcf351dbdf2e0c7d09a571f1b128d752": "-",
                "611e3e038e4296941b2b7cb3d56bcbfa": "A",
                "6bf6ec1ba7cb45b84797068e2c479d42": "B",
                "7fb9359405ffabfc0ca64c654214e249": "C",
                "b8d4231219a00ab0b72c46d634c97d52": "D",
                "4ae13928f17c89e4058b123859bee37e": "E",
                "4cd12a605d0b7283e6e71833a6430e94": "F"
            };
            //判断数组存在且非空
            if (Array.isArray(allValues2) && allValues2.length > 0) {
                for (let j = 0; j < allValues2.length; j++) {
                    const key = allValues2[j];
                    if (GRADE_MAP.hasOwnProperty(key)) {
                        tmp2.push(GRADE_MAP[key]);
                    }
                }
            }

            let tmp22 = tmp2.join("、");
            console.log("ECR版本2 = ", tmp22)

            // 在每个部分之间添加换行符 \n
            let temp =
                `TN编号: ${headData["input_1758781469956_NNEvR"] || ""}
            产品线: ${tmp11 || ""}
            ECR版本: ${tmp22 || ""}
            参加人员: ${headData["systemSelect_1758858798671_9VW1z"] || ""}
            问题描述: ${headData["textarea_1758858798671_Cpl4t"] || ""}
            更改方案: ${headData["textarea_1758858798671_4eMFx"] || ""}
            涉及事项: ${bodyData["body_1758781523014_ZSiUv"] || ""}
            备注: ${bodyData["body_1758781580442_tKM7U"] || ""}`;

            //流程归档时间
            const d = new Date();
            // ES2017 给字符串新增的左侧补全方法
            const pad = n => String(n).padStart(2, '0');
            const str = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} 00:00:00`;

            //钉钉消息推送
            let urlDing = $this.$util.getAPI_URL();
            let formDataDing=new FormData();
            formDataDing.append("userIds",bodyData["body_1758781558990_fVmPx"]);//执行人Id 字符串','拼接
            formDataDing.append("taskName",bodyData["body_1758781523014_ZSiUv"]);//任务名称
            formDataDing.append("distributor",headData.create_user_name);//派发人
            formDataDing.append("planDate",[str,bodyData["body_1758781572995_Ofp3L"].format("YYYY-MM-DD HH:mm:ss")]);//任务计划时间
            urlDing = urlDing.replace("api", "task/dingMessagePush");
            await $this.$http.post(urlDing,formDataDing).then((res) => {
                if(res.data.code===280){
                    $this.$message.success("钉钉消息推送成功")
                }else {
                    $this.$message.errr("系统错误，请联系管理员!!!");
                }
            })

            let saveObj = {
                "bill_id": id,
                "create_user_id": headData.create_user_id,
                "create_user_name": headData.create_user_name,
                "create_dept_name": headData.create_dept_name,
                "bill_type": headData.bill_type,
                "create_dept_id": headData.create_dept_id,
                "bill_no": no,
                "create_company_name": headData.create_company_name,
                "create_date": headData.create_date,
                "create_company_id": headData.create_company_id,
                //系统字段
                "number_1711439316655_41L04": 0,//计划工时
                "number_1711439319768_Hzhsj": 0,//文档数量
                "systemSelect_1711504973428_U0If2": headData.create_user_name,//派发人 默认 创建人
                "systemSelect_1711504973428_U0If2_ID": headData.create_user_id,//派发人ID 默认 创建人ID
                "number_1711505160101_Zy3nM": 0,//任务进度
                "number_1711505281945_eUZOr": 0,//里程碑序号
                "input_1711505283971_PgltR": "false",//里程碑
                "number_1711505313898_96ND4": "0",//任务累计工时
                "input_1711518795031_xvIfW": "1",//任务状态
                "systemSelect_1711520339026_rFF5K": headData.create_company_id,//派发部门
                "systemSelect_1711520339026_rFF5K_ID": headData.create_company_id,//派发部门id
                "select_1711505903223_YWk8w": "cf10c8b9abc315f5849900ddb5d2489c",//TN设计变更
                "input_1751171983502_E4gXx": 0,//计划项目编号
                //新建任务 - 研发评审遗留【项目编号】
                // "input_1718345101976_ZNGth": headData.input_1755331102220_F5VO6,//项目编号
                // "selectStr_1718345029613_IWjr8": 0,//选择项目立项
                // "selectStr_1718345029613_IWjr8_ID":0,//选择项目立项ID
                // "input_1718345101976_PBcTl":  headData.input_1753959378361_PtiNV,//项目名称
                "input_1711439260720_6QPqX": bodyData["body_1758781523014_ZSiUv"],//任务名称
                "rangePicker_1711439307444_Ftzhm": [str, bodyData["body_1758781572995_Ofp3L"].format("YYYY-MM-DD HH:mm:ss")],
                "systemSelect_1711439400905_v5lzI": bodyData["body_1758781565741_2SqTt"],//审核人
                "systemSelect_1711439400905_v5lzI_ID": bodyData["body_1758781565741_2SqTt_ID"],//审核人ID
                "systemSelect_1711439399614_qXQ72": bodyData["body_1758781558990_fVmPx"],//负责人ID//表体的负责人就是任务里面的负责人
                "systemSelect_1711439399614_qXQ72_ID": bodyData["body_1758781558990_fVmPx_ID"],//负责人ID
                "input_1711520372633_i4sGc": headData.create_date,//派发时间
                "textarea_1755766219698_SuIuk": temp,
                // "input_1755832925314_7fNbM":bodyData["body_id"],//技术设计变更ID
                "input_1755832925314_7fNbM": bodyData["table_body_id"],//技术设计变更ID
                "status":2
            }

            let formDataH = new FormData()
            formDataH.append("billId",headData.bill_id); //【注：表头id】
            const isRes = await $this.$http.post("/formsBusiness/gettnrwfenpeiStatus/",formDataH)
            if (isRes.data.code === 280 && isRes.data.data === 2) {
                let files = []
                let formData = new FormData()
                formData.append('obj', JSON.stringify(saveObj))
                formData.append("files", JSON.stringify(files))
                $this.$http.post("/wind/form/save/" + "task" + "/" + "add", formData).then(res => {
                    let data=res.data.data
                    console.log(data)
                }).catch(e => {
                    $this.$message.error(e.message);
                });
            }
        }
    }
}

main()
